package com.ztesoft.sca.thread.threadPool;


import org.apache.log4j.Logger;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;

public class IvrListThreadPool extends ScheduledThreadPoolExecutor {


    private final ThreadLocal<Long> startTime = new ThreadLocal<Long>();
    private static  final Logger logger = Logger.getLogger(IvrListThreadPool.class);

    public IvrListThreadPool(int corePoolSize) {
        super(corePoolSize);
    }

    public IvrListThreadPool(int corePoolSize, ThreadFactory threadFactory) {
        super(corePoolSize, threadFactory);
    }

    public IvrListThreadPool(int corePoolSize, RejectedExecutionHandler handler) {
        super(corePoolSize, handler);
    }

    public IvrListThreadPool(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
        super(corePoolSize, threadFactory, handler);
    }

    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        logger.info("Current Thread is " +t.getName());
        startTime.set(System.currentTimeMillis());
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        logger.info("this task execute cost :"+(System.currentTimeMillis()-startTime.get()) +"ms");
    }
}
